package com.cbhb.sys;

import java.util.PriorityQueue;

public class RecentCounter {

    private PriorityQueue<Integer> priorityQueue;

    public RecentCounter() {
        priorityQueue = new PriorityQueue<>();
    }

    public int ping(int t) {
        priorityQueue.add(t);
        while (true) {
            if (t-3000 > priorityQueue.peek()) priorityQueue.poll();
            else break;
        }
        return priorityQueue.size();
    }

    public static void main(String[] args) {
        RecentCounter recentCounter = new RecentCounter();
        System.out.println(recentCounter.ping(1));
        System.out.println(recentCounter.ping(100));
        System.out.println(recentCounter.ping(3001));
        System.out.println(recentCounter.ping(3002));

    }
}
